package com.nbcio.modules.erp.doc.controller;

import com.nbcio.common.core.domain.R;
import com.nbcio.modules.erp.doc.service.IErpBillService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "ERP流程回调")
@RestController
@RequestMapping("/erp/flow")
@RequiredArgsConstructor
public class ErpFlowCallbackController {

    private final IErpBillService billService;

    // Flowable 审批通过时回调此接口（可在流程模型里配置Http任务）
    @PostMapping("/bill/{id}/approved")
    public R<Boolean> billApproved(@PathVariable("id") String id,
                                   @RequestParam(required = false, defaultValue = "false") boolean autoPost) {
        boolean ok = billService.approve(id);
        if (ok && autoPost) {
            billService.post(id);
        }
        return R.ok(ok);
    }
}


